package com.igoal.dao;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.userdetails.UsernameNotFoundException;
import org.springframework.transaction.annotation.Transactional;

import com.igoal.entity.User;

/**
 * DAO for {@link User} entity
 * @author Tri
 * @since 6/3/2010
 */
public interface UserDAOExt extends GenericDao<User, Long> {
	List<User> findByCriteria(DetachedCriteria criteria);
	
	/**
     * Gets users information based on login name.
     * @param username the user's username
     * @return userDetails populated userDetails object
     * @throws org.springframework.security.userdetails.UsernameNotFoundException thrown when user not found in database
     */
    @Transactional
    UserDetails loadUserByUsername(String username) throws UsernameNotFoundException;

    /**
     * Gets a list of users ordered by the uppercase version of their username.
     *
     * @return List populated list of users
     */
    List<User> getUsers();

    /**
     * Saves a user's information.
     * @param user the object to be saved
     * @return the persisted User object
     */
    User saveUser(User user);

    /**
     * Retrieves the password in DB for a user
     * @param username the user's username
     * @return the password in DB, if the user is already persisted
     */
    String getUserPassword(String username);
    
    /**
     * check whether the email argument is existed or not
     * @param email
     * @return
     */
    boolean existsEmail(String email);
    
    /**
     * check whether the username argument is existed or not
     * @param username
     * @return
     */
    boolean existsUsername(String username);
    
    /**
     * Search friend by some information
     * @param text
     * @return
     */
    List<User> searchUsers(String text, int page);
    
    boolean hasSearchResult(String text, int page);
    
    int countSearchResult(String text);
    
    List<User> searchUsers(String text, int page, String ignoreUserName);
    
    boolean hasSearchResult(String text, int page, String ignoreUserName);
    
    int countSearchResult(String text, String ignoreUserName);
}
